﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Game.Frames;
using System.IO;
using System.Drawing.Text;
using Game.Klassen;
using System.Media;

namespace Game
{
    public partial class controlCredits : UserControl
    {
        #region Initialisieren

        //Eigenschaften
        bool    renderEnabled = true;

        //Hauptfenster und Hintergrundobjekte
        Main                    fenster;
        List<BackGroundObject>  bgObjects;

        //Grafik zum Zeichnen
        Graphics g;
        Image    bm;

        //Letzte Mausposition
        int lastMousePos = 0;
   
        //Konstruktor
        public controlCredits(Main fenster)
        {
            //Hauptfenster setzen
            InitializeComponent();
            this.fenster = fenster;

            //Image und Graphics init
            bm  = (Image)new Bitmap(pbBackground.Width, pbBackground.Height);
            g   = Graphics.FromImage(bm);

            //bgObjects hinzufügen
            bgObjects = new List<BackGroundObject>();
            for(int x = 0; x < this.Width; x++)
                if (x % 100 == 0)
                {
                    bgObjects.Add(new Bubble(new Point(x, Session.rand.Next(0,800)),    new Size(40, 40), true, "left"));
                    bgObjects.Add(new Bubble(new Point(x, Session.rand.Next(100, 800)), new Size(20, 20), true, "right"));
                }

        }
        #endregion

        #region Events
        //Back Hover Image
        private void btBack_MouseEnter(object sender, EventArgs e)
        {
            btBack.Image = Game.Properties.Resources.back_hover;
        }

        private void btBack_MouseLeave(object sender, EventArgs e)
        {
            btBack.Image = Game.Properties.Resources.back_normal;
        }

        //Button Hover
        private void btHover_MouseEnter(object sender, EventArgs e)
        {
            ((Button)sender).Image = Game.Properties.Resources.button_hover;
        }

        private void btHover_MouseLeave(object sender, EventArgs e)
        {
            ((Button)sender).Image = Game.Properties.Resources.button;
        }

        //Zurück zum Menü
        private void btBack_Click(object sender, EventArgs e)
        {
            fenster.showMenu();
        }

        //Letzte Mausposition abfangen
        private void pbBackground_MouseMove(object sender, MouseEventArgs e)
        {
            lastMousePos = ((Control)sender).Location.X + e.X;
        }
        #endregion

        //Rendering Mainloop
        private void mainloop_Tick(object sender, EventArgs e)
        {
            if (renderEnabled)
            {
                //Hintergrund blau malen
                g.Clear(Color.FromArgb(0, 150, 220));

                //Hintergrundebene zeichnen
                g.DrawImage(Game.Properties.Resources.menuBG, -1 * (lastMousePos / 60), 0, 1024, 768);

                //Hintergrundobjekte malen
                foreach (BackGroundObject obj in bgObjects)
                {
                    obj.Update();
                    g.DrawImage(obj.getImage(), obj.position.X + obj.offset.X, obj.position.Y + obj.offset.Y, obj.size.Width, obj.size.Height);
                }

                //Vordergrund Ebenen zeichnen
                g.DrawImage(Game.Properties.Resources.shine, -1 * (lastMousePos / 40), 0, 1024, 768);
                g.DrawImage(Game.Properties.Resources.menuFG, -1 * (lastMousePos / 20), 0, 1024, 768);

                g.DrawString("Schriftart Ghost of Mars - des805"                                            , Session.buttonFont, Brushes.White, new PointF((100 + lastMousePos / 40), 270));
                g.DrawString("Musik Sieg - http://www.matthewpablo.com/services"                            , Session.buttonFont, Brushes.White, new PointF((100 + lastMousePos / 40), 320));
                g.DrawString("Musik Spiel - Eliot Corley"                                                   , Session.buttonFont, Brushes.White, new PointF((100 + lastMousePos / 40), 370));
                g.DrawString("Musik Menü - http://opengameart.org/content/another-space-background-track"   , Session.buttonFont, Brushes.White, new PointF((100 + lastMousePos / 40), 420));

                g.DrawString("Alles andere:"                                                                , Session.buttonFont, Brushes.White, new PointF((100 + lastMousePos / 40), 520));
                g.DrawString("Bastian Emmenecker, Marco Spann, Daniel Kröger und Tobias Viertmann - 2014"   , Session.buttonFont, Brushes.White, new PointF((100 + lastMousePos / 40), 570));

                //Button verschieben
                btBack.Location = new Point(36 + lastMousePos / 40, btBack.Location.Y);

                //Logo Malen
                g.DrawImage(Game.Properties.Resources.font_riseandfall, 200 + (lastMousePos / 40), 10, 625, 250);

                //Picturebox Update
                pbBackground.Image = bm;
            }
        }   
    }
}
